# grapviz dot graph lnguage lexer+parser
%{
#include <stdio.h>
int nlines= 1;
%}


start	= utf  thetype  thename   '{' - (statements)? - '}' { printf("parsed oke.\n"); }

utf	=	(utf8code)?

thetype= 'strict' - 'graph' -
       | 'graph' -
       | 'strict' - 'digraph' -
       | 'digraph' -

thename	= (text)?

ctext= STRING
     | STRING '+' ctext

text= ID
	| STRING
    | FPNUM
    | NUMBER
    | ctext


htext= htmlstring

statements= statement statements
          | statement

statement= statement2
         | statement2 - ';'
         | statement2 - ','

statement2= nstatement
          | estatement
          | astatement
	|  sstatement oattrib

nstatement= nidid oattrib

nidid= text
     | text ';' text
     | text ':' text ':' text

nid= text
   | text ':' text
   | text ':' text ':' text

estatement= nid  erhs  oattrib
	| sstatement erhs  oattrib


erhs= esign nid
	| nid  erhs
    | esign sstatement
    | esign sstatement erhs

erhs= esign nid
	| esign nid  erhs
    | esign sstatement
    | esign sstatement erhs

sstatement= shead '{' statements '}'
	| '{' statements '}'

shead= 'subgraph' text
    | 'subgraph'

astatement= atype tattr
          | aset

atype= 'graph'
     | 'node'
     | 'edge'

aset= text '=' text
    | text '=' htext


sattr= text '=' text
     | text '=' htext

sattr2= sattr
      | text

iattr= sattr2 iattr
     | sattr2 ',' iattr
     | sattr2 ';' iattr


tattr= '[' iattr ']'

oattrib= (tattr oattrib)?

utf8code= 'utf' -

esign='--'
	| '->' -

ID	= < [a-zA-Z_][a-zA-Z_0-9]* > -	{ }
htmlstring = < '<' ID '>' > -
STRING	= '"' < [^\"]* > '"' -	{ }
FPNUM	= < [0-9.]+[0-9]?  >  	-	{ }
NUMBER	= < [0-9]+ >	-	{ }


-=		(space | comment)*
space=		' ' | '\t' | end-of-line
comment=	'#' (!end-of-line .)* end-of-line
end-of-line=	( '\r\n' | '\n' | '\r' )		{ nlines++; }
end-of-file=	!.

%%

int main()
{
  while (yyparse())
    ;
  printf("%d lines\n", nlines);
  return 0;
}
